
import xml


type MessageType dynamic array of record ATTRIBUTE(XMLAll, XMLName="message")
      mtype String ATTRIBUTE(XMLElement,XMLName="type"),
      mname String ATTRIBUTE(XMLElement,XMLName="name"),
      mdata String ATTRIBUTE(XMLElement,XMLName="data"),
      maction String ATTRIBUTE(XMLElement,XMLName="action", XMLOptional)
   end record


main
	define web_component_data string
   define message_rec MessageType

	open window win with form "gridtest"

	input by name web_component_data
      attribute(accept=false, cancel=false, unbuffered, without defaults)

		on action web_component_messages
         call gridtest_deserialize_message(web_component_data, message_rec)

         case message_rec[1].maction
            when "displayperson"
               display by name message_rec[1].*

         end case

      on action close
         exit input
	end input

end main


function gridtest_deserialize_message(s_message, message_rec)
   define s_message String
   define message_rec MessageType
   define doc xml.DomDocument
   define root_node xml.DomNode

   whenever error stop

   try
      call message_rec.clear()

      -- de-serialize the xml message into a record --
      let doc = xml.domDocument.create()
      call doc.loadFromString(s_message)
      let root_node = doc.getDocumentElement()

      call xml.Serializer.DomToVariable(root_node, message_rec[1])
   catch
      display base.application.getStackTrace()
   end try

end function

